package com.mezz.bones.im.logic.strategy;

import com.alibaba.fastjson.JSONObject;
import com.mezz.bones.framework.core.strategy.StrategyContext;
import org.springframework.stereotype.Component;

/**
 * IM回调策略上下文
 */
@Component
public class ImCallbackStrategyFactory {
    private final StrategyContext strategyContext;

    public ImCallbackStrategyFactory(StrategyContext strategyContext) {
        this.strategyContext = strategyContext;
    }

    public Object processCallback(String body) {

        JSONObject jsonObject = JSONObject.parseObject(body);
        String eventType = jsonObject.get("eventType").toString();

        IImCallbackStrategy strategy = strategyContext.getStrategy(IImCallbackStrategy.class, eventType);
        return strategy.process(body);
    }
}